package com.claim;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import com.kmlparser.RouteHistoryParser;
import com.route.Route;
import com.settings.SettingsParameters;

public class ClaimsHistoryClient {
    private String SOAP_ACTION = "claimHistory";
    private String METHOD_NAME = "claimHistory";
    private String NAMESPACE = "http://soap.com/";
    // !!!!! IMPORTANT!!!!! THE URL OF THE WEBSERVER NOT LOCALHOST BECAUSE LOCALHOST IS THE ANDROID EMULATOR !!!!!
    private String URL = "http://172.20.130.229:8080/DistanceWeb/DistanceSOAPService?wsdl";
    private HttpTransportSE androidHttpTransport;
    private SoapSerializationEnvelope envelope;
    private SoapObject request;

    public ClaimsHistoryClient(){

    }

    public ClaimsHistoryClient(String SOAP_ACTION, String METHOD_NAME, String NAMESPACE, String URL){
	this.SOAP_ACTION = SOAP_ACTION;
	this.METHOD_NAME = METHOD_NAME;
	this.NAMESPACE = NAMESPACE;
	this.URL = URL;
    }

    public String claimsHistory(){

	try{
	    request = new SoapObject(NAMESPACE, SOAP_ACTION);
	    request.addProperty("username", SettingsParameters.username);
	    request.addProperty("password", SettingsParameters.password);
	}catch(Exception e){
	    return "You have to verify your login first.";
	}

	try{
	    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
	    envelope.setOutputSoapObject(request);
	    androidHttpTransport = new HttpTransportSE(URL);
	}catch (Exception aE){
	    return "Failed to send";
	}

	try
	{
	    //Object resultRequestSOAP = null; 
	    androidHttpTransport.call(METHOD_NAME, envelope);
	    String resultsRequestSOAP = envelope.getResponse().toString();
	    String results = (String) resultsRequestSOAP;
	    return results;
	}
	catch (Exception aE)
	{
	    return "Failed to send";
	} 
    }
}
